package controller;

import entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import util.JsonUtil;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloWorldController {
    @ModelAttribute
    @RequestMapping("/hello")
//    public ModelAndView helloWorld(HttpServletResponse response) throws IOException {
    public void helloWorld(HttpServletResponse response) throws IOException {
        String message = "Hello World, Spring 3.0!";
        System.out.println(message);
        Person person = new Person("chinalin",21,"男") ;

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        PrintWriter writer = response.getWriter() ;
        String json = JsonUtil.toJson(person) ;
        writer.write(json);
        writer.flush();
        writer.close();
//        return new ModelAndView("hello", "message", message);
    }
}